home *** CD-ROM | disk | FTP | other *** search
- // --------------------------------------------------------------------------------------------------------------
- //
- // MPackMUI V1.01 Peripheral Module
- //
- // --------------------------------------------------------------------------------------------------------------
-
- #include "Peripheral.h"
-
- // --------------------------------------------------------------------------------------------------------------
-
- BOOL DoAslFileReq(char *buffer, char *wholepath, BOOL save)
- {
- struct FileRequester *req;
- char filename[256] = "", directory[256] = "";
- char *filepart;
- struct FileInfoBlock *fib;
- BPTR lock;
-
- // Request a file to open/save to, and store the complete path in the buffer
-
- // N.B. buffer must point to a block of at least 256 bytes of memory
-
- // Extract directory and filename details from path
-
- if ((wholepath[strlen(wholepath) - 1] == ':') || (wholepath[strlen(wholepath) - 1] == '/'))
- {
- // Path only contains a directory (with a leading slash/colon)
-
- strcpy(directory, wholepath);
- } /* if */
-
- else
- {
- // Path contains a directory and/or a filename
-
- if ((lock = Lock(wholepath, ACCESS_READ)) != 0)
- {
- if (!(fib = AllocDosObjectTags(DOS_FIB, TAG_DONE)))
- {
- DoEasyReq("Couldn't allocate FileInfoBlock");
- UnLock(lock);
- CleanUp();
- } /* if */
-
- Examine(lock, fib);
-
- if (fib->fib_DirEntryType > 0)
- {
- // Path contains a directory only
-
- strcpy(directory, wholepath);
- } /* if */
-
- else
- {
- // Path contains a directory and/or a filename
-
- filepart = FilePart(wholepath);
-
- if (strlen(filepart) == strlen(wholepath))
- {
- // Path contains only a filename
-
- strcpy(filename, wholepath);
- } /* if */
-
- else
- {
- // Path contains a directory and a filename
-
- strcpy(filename, filepart);
- strncpy(directory, wholepath, strlen(wholepath) - strlen(filepart));
- directory[strlen(wholepath) - strlen(filepart)] = '\0';
- } /* else */
- } /* else */
-
- FreeDosObject(DOS_FIB, fib);
- UnLock(lock);
- } /* if */
-
- else
- {
- // Path contains either a filename only or a filename and a directory
-
- filepart = FilePart(wholepath);
-
- if (strlen(filepart) == strlen(wholepath))
- {
- // Path contains only a filename
-
- strcpy(filename, wholepath);
- } /* if */
-
- else
- {
- // Path contains a directory and a filename
-
- strcpy(filename, filepart);
- strncpy(directory, wholepath, strlen(wholepath) - strlen(filepart));
- directory[strlen(wholepath) - strlen(filepart)] = '\0';
- } /* else */
- } /* else */
- } /* else */
-
- // Request file
-
- if (!(req = AllocAslRequestTags(ASL_FileRequest, TAG_DONE)))
- {
- DoEasyReq("Warning: couldn't allocate ASL requester");
- return(FALSE);
- } /* if */
-
- if (!(AslRequestTags(req, ASLFR_TitleText, "Select file",
- ASLFR_RejectIcons, TRUE,
- ASLFR_InitialDrawer, directory,
- ASLFR_InitialFile, filename,
- ASLFR_DoSaveMode, save,
- TAG_DONE)))
- {
- // User cancelled requester
-
- FreeAslRequest(req);
- return(FALSE);
- } /* if */
-
- // Create complete path
-
- strcpy(buffer, req->fr_Drawer);
-
- AddPart(buffer, req->fr_File, 256);
-
- FreeAslRequest(req);
-
- return(TRUE);
- } /* DoAslFileReq() */
-
- // --------------------------------------------------------------------------------------------------------------
-
- BOOL DoAslDirReq(char *buffer, char *path)
- {
- struct FileRequester *req;
-
- // Request a directory, and store the path in the buffer
-
- // N.B. buffer must point to a block of at least 256 bytes of memory
-
- if (!(req = AllocAslRequest(ASL_FileRequest, TAG_DONE)))
- {
- DoEasyReq("Warning: couldn't allocate ASL requester");
- return(FALSE);
- } /* if */
-
- if (!(AslRequestTags(req, ASLFR_TitleText, "Select directory",
- ASLFR_DrawersOnly, TRUE,
- ASLFR_RejectIcons, TRUE,
- ASLFR_InitialDrawer, path,
- TAG_DONE)))
- {
- // User cancelled requester
-
- FreeAslRequest(req);
- return(FALSE);
- } /* if */
-
- // Create path
-
- strcpy(buffer, req->fr_Drawer);
-
- FreeAslRequest(req);
-
- return(TRUE);
- } /* DoAslDirReq() */
-
- // --------------------------------------------------------------------------------------------------------------
-
- void DoEasyReq(char *message)
- {
- // EasyRequest with a message
-
- struct EasyStruct req = {
- sizeof(struct EasyStruct),
- 0,
- "MPackMUI V1.01",
- message,
- "OK!"
- };
-
- EasyRequest(NULL, &req, NULL, NULL);
- } /* DoEasyReq() */
-
- // --------------------------------------------------------------------------------------------------------------
-
- // End Of Text
-